package easy.删除排序链表中的重复元素;

/**
 * 删除排序链表中的重复元素
 *
 * @author CodeX
 * @since 2021-09-28 16:45:19
 */
public class DeleteDuplicates {
    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null) { return head; }

        ListNode node = head;
        while (head.next != null){
            if (head.val == head.next.val){
                head.next = head.next.next;
            }else {
                head = head.next;
            }
        }
        return node;
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(1);
        head.next.next = new ListNode(2);
        head.next.next.next = new ListNode(2);
        head.next.next.next.next = new ListNode(3);
        head.next.next.next.next.next = new ListNode(3);
        System.out.println(head);
        System.out.println(deleteDuplicates(head));
    }
}
